"use strict";
cc._RF.push(module, '9b6d9aaWHRHu68+Pvid/f8k', 'level_peopleArchery_openBoxPage');
// scripts/levelBundles/level_PeopleArchery/page/level_peopleArchery_openBoxPage.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var MainRoot_1 = require("../../../Game/MainRoot");
var gameEngine_1 = require("../../../engines/gameEngine");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var level_peopleArchery_openBoxPage = /** @class */ (function (_super) {
    __extends(level_peopleArchery_openBoxPage, _super);
    function level_peopleArchery_openBoxPage() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.itemContent = null;
        _this.item = null;
        _this.lbBtn = null;
        _this.level = null;
        _this.datas = [];
        _this.curSelectItem = null;
        _this.completeFun = null;
        return _this;
    }
    level_peopleArchery_openBoxPage.prototype.bindData = function (datas, level, completeFun) {
        this.datas = datas;
        console.log(datas, ">>>>>>>>");
        this.level = level;
        this.completeFun = completeFun;
        this.refrenshPage();
    };
    level_peopleArchery_openBoxPage.prototype.onSelectOne = function (e) {
        this.itemContent.children.forEach(function (n) {
            n.getChildByName("select").active = false;
        });
        this.curSelectItem = e.target;
        this.curSelectItem.getChildByName("select").active = true;
    };
    level_peopleArchery_openBoxPage.prototype.refrenshPage = function () {
        this.lbBtn.string = "双倍获取";
        var _loop_1 = function (i) {
            var item = cc.instantiate(this_1.item);
            var icon = item.getChildByName("icon").getComponent(cc.Sprite);
            MainRoot_1.default.LevelSystem.getOneTypeBundle(this_1.level.getLevelInfo().levelType).load("dialog/" + (this_1.datas[i].param_type == "6" ? "gong" : "xue"), cc.SpriteFrame, function (err, spf) {
                if (err) {
                    console.log("加载图片失败");
                    return;
                }
                icon.spriteFrame = spf;
            });
            var count = Number(this_1.datas[i].option_param);
            var optionText = gameEngine_1.default.getManagers().peopleArcheryManager.parseDataAsOptionText(this_1.datas[i]);
            var lbParam = item.getChildByName("layout").getChildByName("lbDesc").getComponent(cc.Label);
            var lbCount = item.getChildByName("layout").getChildByName("lbCount").getComponent(cc.Label);
            lbParam.string = optionText + ":";
            console.log(optionText, "?????");
            lbCount.string = count.toString();
            item.setParent(this_1.itemContent);
            item.on('touchend', this_1.onSelectOne, this_1);
        };
        var this_1 = this;
        for (var i = 0; i < this.datas.length; i++) {
            _loop_1(i);
        }
        if (this.datas.length <= 1) {
            this.curSelectItem = this.itemContent.children[0];
            this.curSelectItem.getChildByName("select").active = true;
        }
    };
    level_peopleArchery_openBoxPage.prototype.update = function (dt) {
        this.level.gamePauseFlag = true;
    };
    level_peopleArchery_openBoxPage.prototype.onBtnComit = function () {
        if (!this.curSelectItem) {
            gameEngine_1.default.getModules().uiControlModule.showMessageBox("请选择奖励");
        }
        else {
            this.closePage();
        }
    };
    level_peopleArchery_openBoxPage.prototype.onBtnGetBullet = function () {
        var _this = this;
        if (!this.curSelectItem) {
            gameEngine_1.default.getModules().uiControlModule.showMessageBox("请选择奖励");
        }
        else {
            if (gameEngine_1.default.getServices().userSrv.getCoins() > 0) {
                gameEngine_1.default.getServices().userSrv.setCoins(-1, true);
                // if(this.completeFun){ 
                //     for(let i = 0;i<this.datas.length;i++){
                //         this.level.parseDataAddPeople(this.datas[i]);
                //     }
                // }else{
                //     this.getBullet();
                // }
                var silbilingIndex = this.curSelectItem.getSiblingIndex();
                var data = this.datas[silbilingIndex];
                this.level.parseDataAddPeople(data);
                this.closePage();
            }
            else {
                gameEngine_1.default.getServices().miniGameSrv.getAppApiInstance().loadAndShowVideoAd(function () {
                    // if(this.completeFun){ 
                    //     for(let i = 0;i<this.datas.length;i++){
                    //         this.level.parseDataAddPeople(this.datas[i]);
                    //     }
                    // }else{
                    //     this.getBullet();
                    // }
                    var silbilingIndex = _this.curSelectItem.getSiblingIndex();
                    var data = _this.datas[silbilingIndex];
                    _this.level.parseDataAddPeople(data);
                    _this.closePage();
                }, function () {
                }, null, "看广告获得子弹");
            }
        }
    };
    level_peopleArchery_openBoxPage.prototype.getBullet = function () {
        this.level.parseDataAddPeople({ param_type: "4", option_param: 1 });
    };
    level_peopleArchery_openBoxPage.prototype.closePage = function () {
        // for(let i = 0;i<this.datas.length;i++){
        //     this.level.parseDataAddPeople(this.datas[i]);
        // }
        var silbilingIndex = this.curSelectItem.getSiblingIndex();
        var data = this.datas[silbilingIndex];
        this.level.parseDataAddPeople(data);
        this.level.gamePauseFlag = false;
        this.completeFun && this.completeFun();
        this.node.destroy();
        this.node.removeFromParent();
    };
    __decorate([
        property({ type: cc.Node, tooltip: "itemcontent" })
    ], level_peopleArchery_openBoxPage.prototype, "itemContent", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "item" })
    ], level_peopleArchery_openBoxPage.prototype, "item", void 0);
    __decorate([
        property({ type: cc.Label, tooltip: "按钮文本" })
    ], level_peopleArchery_openBoxPage.prototype, "lbBtn", void 0);
    level_peopleArchery_openBoxPage = __decorate([
        ccclass
    ], level_peopleArchery_openBoxPage);
    return level_peopleArchery_openBoxPage;
}(cc.Component));
exports.default = level_peopleArchery_openBoxPage;

cc._RF.pop();